﻿@model  DHQGHN.DAL.Common.DataPage<DHQGHN.PM2.Models.DonViModel>
@{
    var pagNar = ViewBag.Pagination as DHQGHN.DAL.Common.Pagination;
    var lstItem = Model.Data;
}
<link href="~/Content/index.css" rel="stylesheet" />
<div id="gridContent" align="center" style="padding:10px;">
    @*<script>
            var recordCount = '48';
            var startRecord = '1';
            var endRecord = '10';
        </script>*@
    <table class="webGrid table table-striped table-bordered table-hover dataTable no-footer" id="ds_don_vi">
        <thead>
            <tr class="header">
                <th scope="col" style="width:45px">
                    STT
                </th>
                <th scope="col" style="max-width:100px; min-width:50px; width: 100px;">
                    Mã ĐV
                </th>
                <th scope="col" style="max-width:100px; min-width:50px; width: 100px;">
                    Viết tắt
                </th>
                <th scope="col" style="max-width:300px; min-width:150px; width: 250px;">
                    Tên đơn vị
                </th>
                <th scope="col" style="max-width:300px; min-width:150px; width: 250px;">
                    Nhóm đơn vị cơ bản
                </th>
                <th scope="col" style="max-width:120px; min-width:50px; width: 100px;">
                    Nhiện vụ
                </th>
                <th scope="col" style="max-width:150px; min-width:50px; width: 200px;">
                    Ghi chú
                </th>
                <th scope="col" style="text-align: center; width: 65px; min-width: 65px;">
                    Thao tác
                </th>
            </tr>
        </thead>
        <tbody>
            @if (Model.Data.Any())
            {
                for (int i = 0; i < lstItem.Count; i++)
                {
                    string strCoQuyenGiamSat = "Chỉ báo cáo";
                    if (lstItem[i].IntCoQuyenGiamSat == 1) { strCoQuyenGiamSat = "Chỉ giám sát"; }
                    else if (lstItem[i].IntCoQuyenGiamSat == 2) { strCoQuyenGiamSat = "Báo cáo và giám sát"; }
                    <tr class="webgrid-row-style">
                        <td class="clsSTT" style="text-align: center;">
                            <span>@(i + 1 + pagNar.CurrentPage * pagNar.PageSize)</span>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].MaDonVi
                            </span>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TenVietTat
                            </span>
                        </td>
                        <td>
                            <div id="spnFullName" class="hidden-400">@lstItem[i].TenDonVi</div>
                            <div class="display-400"><b>@lstItem[i].TenDonVi</b></div>
                            @*<span class="display-480">Tên nhóm ĐV: @lstItem[i].TenNhomDonVi</span>*@
                            @*<span class="display-480">Ghi chú: @lstItem[i].GhiChu</span>*@
                        </td>
                        <td class="hidden-400">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TenNhomDonVi
                            </span>
                        </td>
                        <td class="clsUserName hidden-100">
                            <span id="spnUserName" class="display-mode">
                                @strCoQuyenGiamSat
                            </span>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].GhiChu
                            </span>
                        </td>
                        <td class="action">
                            <div style="text-align:center;">
                                <div class="btn-group">
                                    <a href="#" data-toggle="dropdown" class="btn btn-lg" style="margin:0px; padding:0px;">
                                        <div class="label label-info">
                                            <i class="fa fa-th"></i>
                                        </div>
                                    </a>
                                    <ul class="dropdown-menu no-angle pull-right right">
                                        <li>
                                            <a onclick="donviEdit(@lstItem[i].DonViId)" data-index="@lstItem[i].DonViId" style="cursor:pointer;"> <i class="fa fa-pencil"></i> Cập nhật thông tin</a>
                                        <li>
                                            <a onclick="nhomdonviEdit(@lstItem[i].DonViId)" data-index="@lstItem[i].DonViId" style="cursor:pointer;"> <i class="fa fa-edit"></i> Chọn nhóm đơn vị</a>
                                        </li>
                                        <li>
                                            <a onclick="actionDelete(@lstItem[i].DonViId)" data-index="@lstItem[i].DonViId" style="cursor:pointer;"> <i class="fa fa-trash-o"></i> Xóa thông tin</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr>
                    <td colspan="9"><p style="width: 100%; text-align:center;">Không tìm danh mục nào.</p></td>
                </tr>
            }
        </tbody>
        @if (Model.Data.Any())
        {
            <tfoot>
                @*<tr>
                        <td colspan="9" style="text-align:left;height:25px">
                            <button type="button" class="btn btn-danger" title="Xóa bằng cấp" id="btnDelete" style="height: 25px; margin-top: 5px; padding-top: 3px;">
                                Ngừng sử dụng
                            </button>
                        </td>
                    </tr>*@

                <tr>
                    <td colspan="9">
                        @if (Model.Data.Any())
                        {
                            @Html.Partial("_PaginationView", pagNar)
                        }
                    </td>
                </tr>
            </tfoot>
        }


    </table>



    <script type="text/javascript">
        $(function () {
            $('.clsSTT').css('text-align', 'center');
            var colsHeader = $('#gridContent th');
            //$(colsHeader[2]).addClass('hidden-480');
            //$(colsHeader[3]).addClass('hidden-580');
            //$(colsHeader[4]).addClass('hidden-780');
            //$(colsHeader[5]).css('text-align', 'center').css('width', '50px');
        });
    </script>
</div>

<script>
    @functions{
            public string GetAntiForgeryToken()
            {
                string cookieToken, formToken;
                AntiForgery.GetTokens(null, out cookieToken, out formToken);
                return cookieToken + "," + formToken;
            }
        }
</script>
<script type="text/javascript">
   

    $(document).ready(function () {

        $('.country-edit').bind('click', function (event) {
            functionCreateOrUpdate($(this).attr('data-id'), "Cập nhật")
        });

        $('.country-active').bind('click', function (event) {
            activeCertification($(this).attr('data-id'))
        });

        $('#btnDelete').click(function () {
            var values = [];
            $('#checkbox input:checked').each(function () {
                values.push(this.name);
            });
            if (values.length != 0) {
                var $self = $(this);
                comfirmDelete(messager.confirmUnuse, function () {
                    $.ajax("/Certification/ActionDelete", {
                        type: "post",
                        contentType: "application/json",
                        data: JSON.stringify({ listID: values }), // JSON data goes here
                        dataType: "json",
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        success: function (response) {
                            if (response.status == 200) {
                                OnCriteria(currentPageIndex);
                                window.notice(response.result, window.notice_success);
                            }
                            else {
                                window.notice(response.result, window.notice_error);
                            }
                        },
                    });
                }, null, "Thông báo");
            } else {
                warning(messager.selectRecord, "Thông báo");
            }
        });
    });

    function actionDelete(id) {

        var box = bootbox.dialog({
            title: "Xóa nhóm đơn vị",
            message: "Bạn có chắc chắn xóa đơn vị này không?",
            onEscape: function () {
                box.modal('hide');
            },
            buttons: {
                success: {
                    label: "<i class='fa fa-warning'></i> Xóa",
                    className: "btn btn-sm btn-danger", //btn-success
                    callback: function () {
                        $("#divLoading").show();
                        $.ajax({
                            url: '/NhomDonVi/ActionDelete',
                            headers: headers,
                            data: {
                                id: id
                            },
                            //dataType: 'json',
                            type: 'post',
                            success: function (response) {
                                if (response != null && response.status == 200) {
                                    Layout.toastr("", response.result);
                                    OnCriteria(0);
                                    result = true;
                                } else {
                                    Layout.toastr("", response.result);
                                }
                                $("#divLoading").hide();
                            },
                            complete: function () {

                            },
                            error: function (ex) {
                                alert(JSON.stringify(ex));
                            }
                        });

                    }
                },
                danger: {
                    label: "<i class='fa fa-reply'></i> Hủy bỏ",
                    className: "btn btn-sm btn-default",//"btn-danger",
                    callback: function () {
                    }
                }
            }
        });
    }

</script>